#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

class LifeGame{
  int R, C, gen; // 行、列、代
  vector<string> grid; // 世界网格
public:
  LifeGame(int tr, int tc);
  LifeGame(LifeGame& g);
  void swap(LifeGame& g);
  void load(istream& ist);
  void randomize(double live_ratio);
  void evolve();
  void save(ostream& ost) const;
  void set_gen(int x) { gen = x; }
  int get_gen() const { return gen; }
};

LifeGame::LifeGame(int tr, int tc)
  : R(tr), C(tc), gen(0), grid(R){
  for(int r = 0; r < R; ++r){
    grid[r].resize(C);
  }
}

LifeGame::LifeGame(LifeGame& g)
  : R(g.R), C(g.C), gen(g.gen), grid(g.grid){
}

void LifeGame::swap(LifeGame& g){
  std::swap(R, g.R);
  std::swap(C, g.C);
  std::swap(gen, g.gen);
  std::swap(grid, g.grid);
}

void LifeGame::load(istream& ist) {
  for(int r = 0; r < R; ++r){
    getline(ist, grid[r]);
  }
}

void LifeGame::randomize(double live_ratio){
  for(int r = 0; r < R; ++r){
    string& s = grid[r];
    for(int c = 0; c < C; ++c){
      s[c] = ((rand() % 10000 * 0.0001) < live_ratio ? '#' : '.');
    }
  }
}

void LifeGame::evolve(){
  ++gen;
  // TODO: 演化一代
}

void LifeGame::save(ostream& ost) const {
  ost << R << ' ' << C << ' ' << gen << '\n';
  for(int r = 0; r < R; ++r){
    ost << grid[r] << '\n';
  }
}

int main(){
  for(int R, C, G; cin >> R >> C >> G >> ws;){
    LifeGame game(R, C);
    game.load(cin);
    for(int i = 0; i < G; ++i){ // 演化G代
      game.evolve();
    }
    assert(game.get_gen() == G);   
    game.save(cout);
  }
  return 0;
}